package cn.lenchu.data.h2.converter;

import cn.lenchu.data.h2.entity.GroupEntity;
import cn.lenchu.data.model.Group;
import org.springframework.beans.BeanUtils;

import java.sql.Timestamp;

/**
 * @author lenchu
 */
public class GroupConverter {

    public static Group toGroup(GroupEntity groupEntity) {
        Group group = new Group();
        BeanUtils.copyProperties(groupEntity, group, "createTime");
        if (groupEntity.getCreateTime() != null) {
            group.setCreateTime(groupEntity.getCreateTime().getTime());
        }
        return group;
    }

    public static GroupEntity toGroupEntity(Group group) {
        GroupEntity groupEntity = new GroupEntity();
        BeanUtils.copyProperties(group, groupEntity, "createTime");
        if (group.getCreateTime() != null) {
            groupEntity.setCreateTime(new Timestamp(group.getCreateTime()));
        }
        return groupEntity;
    }
}
